package com.sky.controller.admin;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("AdminShopController")
@RequestMapping("admin/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    private final String key = "SHOP_STATUS";
    /**
     * 营业状态设置
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation(value = "营业状态设置")
    public Result setShopStatus(@PathVariable Integer status){
        log.info("设置店铺的营业状态为:{}",status == 1? "营业中":"打烊中");
        redisTemplate.opsForValue().set(key,status);
        log.info("店铺当前的营业状态为：{}",redisTemplate.opsForValue().get("SHOP_STATUS"));
        return Result.success();
    }


    /**
     * 查询店铺营业状态
     * @return
     */
    @GetMapping("/status")
    @ApiOperation(value = "查询店铺营业状态")
    public Result<Integer> getShopStatus(){
        Integer result =  (Integer) redisTemplate.opsForValue().get("SHOP_STATUS");
        log.info("店铺当前的营业状态为:{}",result == 1? "营业中":"打烊中");
        System.out.println(result);
        return Result.success(result);
    }
}
